<template>
	<view>
		<button type="default" @tap="sendcode">发送验证码</button>
		<button type="default" @tap="toRegister">注册</button>
		<button type="default" @tap="toLogin">登录</button>
		<button type="default" @tap="toMy">我的</button>
	</view>
</template>

<script>
	import { sendcode,register,login,postuserinfo } from '../../api/api.js'
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			sendcode(){
				let that = this
				let params = {
					"phone_number": "13265840670"
				}
				sendcode(params).then(res => {
					console.log(res)
				})
			},
			toRegister(){
				let that = this
				let params = {
					"access_token":"wxc12e65ecba8895fc",
					"phone_number":"13265840670",
					"captcha":"870048",
					"nick_name":"星星",
					"avatar":""
				}
				register(params).then(res => {
					console.log(res)
				})
			},
			toLogin(){
				let that = this
				let params = {
					"access_token":"wxc12e65ecba8895fc",
				}
				login(params).then(res => {
					console.log(res)
					console.log(res.data.data.token)
					uni.setStorage({
					    key: 'TOKEN',
					    data: res.data.data.token,
					    success: function () {
					        console.log('success');
							// uni.getStorage({
							// 	key: 'TOKEN',
							// 	success: function (res) {
							// 		console.log(res.data);
							// 	},
							// })
							console.log(uni.getStorageSync('TOKEN'))
					    }
					});
					
				})
			},
			toMy(){
				let that = this
				// let params = {
				// 	// "access_token":"wxc12e65ecba8895fc",
				// }
				// postuserinfo(params).then(res => {
				// 	console.log(res)
					
				// })
				console.log(uni.getStorageSync('TOKEN'))
				uni.request({
				    url: 'http://59.110.116.232:8085/User/v1/getuserinfo', //仅为示例，并非真实接口地址。
					method: 'POST',
				    params: {},
				    header: {
				        'Authorization': "Bearer " + uni.getStorageSync('TOKEN') //自定义请求头信息
				    },
				    success: (res) => {
				        console.log(res);
				        
				    }
				});
			}
		}
	}
</script>
